// pages/beautiful/beautiful.js
var list_img = [];
var url = wx.getStorageSync('url') 
var shopid = wx.getStorageSync('shopid') 
var userId = wx.getStorageSync('userId') 
var time_ss = wx.getStorageSync('time_ss')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userId = wx.getStorageSync('userId') 
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    console.log(shopid)
    console.log(userId)

    // 获取商品分类
    wx.request({
      url: url +'gateWare/mpInitWareClass',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": { "shopId": shopid}
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        var data = e.data.content
        for (let i = 0; i < e.data.content.length;i++){
          list_img.push(data[i].imgSrc)
        }
        that.setData({
          gateWare: data,
          img_src: list_img[0]
        })
      }
    })
    // 获取商品分类下面的商品
    wx.request({
      url: url +'gateWare/mpSearchWa',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "shopId": shopid,
          "id": "1"
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        wx.hideLoading()
        var data = e.data.content
        var data_s = e.data       
        that.setData({
          searchWare: data
        })
      }
    })
  },
  swichNav:function(e){
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    var idx = e.currentTarget.dataset.current
    var id = e.currentTarget.id
    var that = this
    that.setData({
      currentTab: e.currentTarget.dataset.current,
      img_src: list_img[idx]
    })
    // 获取商品分类下面的商品
    wx.request({
      url: url + 'gateWare/mpSearchWa',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "shopId": shopid,
          "id": id
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        var data = e.data.content
        that.setData({
          searchWare: data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  // 商品详情
  goto_xiangqing: function (e) {
    console.log(e.currentTarget.dataset)
    var activityid = e.currentTarget.dataset.activityid
    var tag = e.currentTarget.dataset.tag
    var wareid = e.currentTarget.dataset.wareid
    if (tag==2){
      wx.navigateTo({
        url: '../index/BeautyKilling/kill_details/kill_details?wareId=' + wareid + '&activityId=' + activityid,
      })
    }
    if (tag == 1){
      wx.navigateTo({
        url: '../index/MeteorFall/Star_details/Star_details?wareId=' + wareid + '&activityId=' + activityid,
      })
    }
    wx.navigateTo({

    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var height = wx.getSystemInfoSync().windowHeight;
    var width = Math.floor((wx.getSystemInfoSync().windowWidth*0.74-50)/3);
    that.setData({
      height: height,
      width: width
    }) 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})